﻿using System;
using System.ServiceProcess;
using NLog;

namespace TfsGiggle.EngineService
{
    static class Program
    {
        private static Logger _logger = LogManager.GetCurrentClassLogger();

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
			{ 
				new TfsGiggleService() 
			};
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            ServiceBase.Run(ServicesToRun);
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception; 
            if (ex == null) ex = new Exception(e.ExceptionObject.ToString());
            _logger.FatalException("Unhandled exception caught.", ex);
        }
    }
}
